package com.aabte.auth.account.resource.facade;

import com.aabte.auth.account.application.AccountService;
import com.aabte.auth.account.domain.model.Account;
import com.aabte.auth.account.domain.model.AccountId;
import com.aabte.auth.account.domain.model.AccountName;
import com.aabte.auth.account.domain.model.Password;
import com.aabte.auth.account.resource.api.auth.AuthAccountDTO;
import com.aabte.auth.account.resource.facade.assembler.AuthAccountDTOAssembler;
import com.aabte.auth.util.JwtUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class AuthServiceFacade {

    @Resource
    private AccountService accountService;

    public String token(String accountName, String accountPassword) {
        Account account = accountService.account(new AccountName(accountName), new Password(accountPassword));
        return JwtUtil.createJwt(account);
    }

    public AuthAccountDTO account(String accountId) {
        Account account = accountService.account(new AccountId(accountId));
        AuthAccountDTOAssembler assembler = new AuthAccountDTOAssembler();
        return assembler.toDTO(account);
    }
}
